﻿//删除读者信息
void DeleteReader()
{
	FILE* pfReader;
	int ReaderID;
	int ReaderRecord;
	char Flag;

	system("cls");
	ReaderID = SearchReader();
	cout << endl;
	//文件打开失败
	if (ReaderID == -1)
	{
		return;
	}
	if (ReaderID == -3)
	{
		return;
	}

	ReaderRecord = ReadReaderFile("rb");
	cout << "\t已经找到该读者，是否删除(y/n)：";
	cin >> Flag;
	cout << endl;

	int index = astReader[ReaderID].Num;//删除的信息编号

	//把要删除的记录后的数组全部向前移动一位，然后再写入文件中
	if (Flag == 'n')
	{
		return;
	}
	else if (Flag == 'y')
	{
		for (int i = ReaderID; i < ReaderRecord - 1; i++)
		{
			astReader[i] = astReader[i + 1];
		}
		ReaderRecord--;
	}

	//写入文件
	if (Flag == 'y')
	{
		pfReader = fopen("reader.txt", "wb");
		if (pfReader != NULL)
		{
			for (int i = 0; i < ReaderRecord; i++)
			{
				if (fwrite(&astReader[i], LEN_READER, 1, pfReader) != 1)
				{
					cout << "\t无法保存该信息" << endl;
					return;
				}
			}
			fclose(pfReader);
			cout << "\t" << index << "号图书信息已经成功删除" << endl;
		}
	}
	else
	{
		cout << "\t输入错误，请退出重新输入" << endl;
	}
}
